#pragma once
#include "uipopup.h"
#include "base/win/scoped_gdi_object.h"
#include "pps/codeRate.h"
#include "uipopupbase.h"

//////////////////////////////////////////////////////////////////////////
class CCodeRate;
class CPopupUI;
//////////////////////////////////////////////////////////////////////////

class CCodeRateMgr
{
public:
	CCodeRateMgr(HWND parent);
	~CCodeRateMgr();

public:
	/**
	@brief	initialize the pointer of coderate button in ctrlpanel.
	@note	this must be invoke before run.
	*/
	void init(CButtonUI* coderate_ptr);

	/**
	@brief	show code rate info.
	*/
	void run(scoped_refptr<CCodeRate> coderate);

	/**
	@brief	clear the code rate info.
	*/
	void clear();

	/**
	@brief	show code rate button position.
	*/
	void setpos(RECT rect);

	/**
	@brief	show or hide code rate button.
	*/
	void show(bool shown);

	/**
	@brief	update the item.
	*/
	void update();

private:
	/**
	@brief	create code rate switch window.
	*/
	void create(HWND parent);

	/**
	@brief	notify event.
	*/
	bool notify(void* notify_msg);

	/**
	@brief	size event.
	*/
	bool event(void* param);

	/**
	@brief	tip close event.
	*/
	bool onTipClose(void* notify_msg);

	/**
	@brief	update menu.
	*/
	void updateMenu(bool shown);

	/**
	@brief	update the coderate button.	
	*/
	bool updateCodeRate(CButtonUI* button, const CoderateInfo* info);

	/**
	@brief	update tips.
	*/
	void updateTip();

	/**
	@brief	click to switch the coderate.
	*/
	void clickHDItem(CButtonUI* button);

	/**
	@brief	close tip window.
	*/
	void closeTip();

	/**
	@brief	generate the image of coderate.
	*/
	bool genCodeRateImage(CButtonUI* button, const CoderateInfo* info);

private:
	bool show_able_;						///< whether the coderate button is showing.
	scoped_refptr<CCodeRate> coderate_now_;	///< coderate info.
	CButtonUI* code_rate_ptr_;				///< pointer of coderate button in ctrlpanel.

    scoped_ptr<CXPopup> menu_ptr_;			///< coderate menu pointer.
	CVerticalLayoutUI* code_rate_menu_ptr_; ///< coderate menu root pointer.
	CButtonUI* code_rate_menu_now_ptr_;		///< pointer of current coderate in menu .
	SIZE menu_size_;						///< size of coderate menu.
	bool menu_show_;
	bool menu_repaint_;

	scoped_ptr<CPopupUI> tips_ptr_;			///< coderate tips pointer.
	SIZE tip_size_;							///< size of coderate tip.
	bool code_rate_tip_;					///< whether show coderate switch tips.

    HWND parent_;
	DISALLOW_COPY_AND_ASSIGN(CCodeRateMgr);
};

